<template>
  <div class="sort-list">
    <Draggable
      v-model:value="modelList"
      :list="sortList"
      :animation="100"
      item-key="id"
      class="list-group"
      :force-fallback="true"
      ghost-class="ghost"
    >
      <template #item="{ element }">
        <div class="item">
          <i class="ifont-wid-equipment_icon_sort"></i>
          <i class="ifont-wid-equipment_icon_dapin"></i>
          <span class="title">{{ element.name }}</span>
          <span>({{ element.quantity }})</span>
        </div>
      </template>
    </Draggable>
    <div v-if="sortList.length === 0" class="no-list">
      <Empty :image="simpleImage" />
    </div>
  </div>
</template>
<script setup>
import Draggable from 'vuedraggable';
import { ref, defineProps, defineExpose, defineEmits, onMounted } from 'vue';
import { getDeviceList } from '@/api/user';
import { Empty } from 'ant-design-vue';
const props = defineProps({
  sortList: {
    type: Array,
    default: () => []
  }
});
const simpleImage = ref(require('@/assets/images/noData@2x.png'));
const modelList = ref([]);
const emit = defineEmits(['SortlistData', 'unsortData']);
/** **方法区域 ** **/
// 保持排序
function KeepSorting() {
  emit('SortlistData', props.sortList);
}
// 取消排序
function unsort() {
  // 获取列表的数据
  let data = localStorage.getItem('modelList');
  emit('unsortData', JSON.parse(data));
}
defineExpose({
  KeepSorting,
  unsort
});
</script>
<style lang="less" scoped>
.sort-list {
  border-radius: 5px;
  width: 100%;
  height: 100%;
  margin-top: 16px;
  border: 1px solid #e1dddd;
  padding: 0 16px;
  .item {
    height: 56px;
    border-bottom: 1px solid #dadee0;
    display: flex;
    align-items: center;
    font-size: 16px;
    color: #222;
    cursor: move;
    &:last-child {
      border-bottom: none;
    }
    .ifont-wid-equipment_icon_sort {
      margin-right: 16px;
      color: #999999;
      font-size: 16px;
    }
    .ifont-wid-equipment_icon_dapin {
      color: #d6aa56;
      margin-right: 8px;
      font-size: 16px;
      margin-top: 2px;
    }
    .ifont-wid-equipment_icon_sort:hover {
      color: #d6aa56;
    }
  }
  .no-list {
    height: 610px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
}
</style>
